home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / OFDb - IMDb (DE).ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  12.4 KB  |  405 lines

  1. // GETINFO SCRIPTING
  2. // Combined OFDb / IMDb (DE) import with description from OFDb. All other informations from IMDb
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *  Online-Filmdatenbank(OFDb),                      *
  7.  *   http://www.ofdb.de                            *
  8.  *            and                                  *
  9.  *  Internet Movie Database (IMDb),                *
  10.  *   http://us.imdb.com                            *
  11.  *                                                 *
  12.  *  (c) 2002 Fabian Filipczyk    FFJaro@gmx.de     *
  13.  *                                                 *
  14.  *     Modified by Bad Joker    badjoker@gmx.net   *
  15.  *                                                 *
  16.  *  For use with Ant Movie Catalog 3.3.0           *
  17.  *  www.antp.be/software/moviecatalog              *
  18.  *                                                 *
  19.  *  This program is free software; you can         *
  20.  *  redistribute it and/or modify it under the     *
  21.  *  terms of the GNU General Public License as     *
  22.  *  published by the Free Software Foundation;     *
  23.  *  either version 2 of the License, or (at your   *
  24.  *  option) any later version.                     *
  25.  ***************************************************)
  26.  
  27. program OFDB_DE;
  28. var
  29.   MovieName, IMDbURL, GerIMDbDURL: string;
  30.  
  31. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  32. var
  33.   i: Integer;
  34. begin
  35.   result := -1;
  36.   if StartAt < 0 then
  37.     StartAt := 0;
  38.   for i := StartAt to List.Count-1 do
  39.     if Pos(Pattern, List.GetString(i)) <> 0 then
  40.     begin
  41.       result := i;
  42.       Break;
  43.     end;
  44. end;
  45.  
  46. procedure AnalysePage(Address: string);
  47. var
  48.   Page: TStringList;
  49.   LineNr: Integer;
  50. begin
  51.   Page := TStringList.Create;
  52.   Page.Text := GetPage(Address);
  53.   if pos('<title>OFDb - Übersicht der Filmdaten</title>', Page.Text) > 0 then
  54.   begin
  55.     AnalyseOFDBPage(Page)
  56.     AnalyseIMDBDPage(Page)
  57.     AnalyseIMDBPage(Page)
  58.     DisplayResults
  59.   end else
  60.   begin
  61.     if pos('Titel:</b><br><br><b>•</b> <i>Keine Ergebnisse</i>', Page.Text) > 0 then
  62.     begin
  63.       ShowMessage('Keine Ergebnisse unter dem Titel zu finden, bitte den Titel des Filmes Σndern!');
  64.       if (MovieName <> '') or Input('OFDb', 'Bitte einen alternativen Titel eingeben :', MovieName) then
  65.         begin
  66.         AnalysePage('http://www.ofdb.de/view.php?page=suchergebnis&SText='+UrlEncode(MovieName)+'&Kat=All');
  67.         end;
  68.   end else
  69.   begin
  70.     PickTreeClear;
  71.     LineNr := FindLine('<b>Titel:</b>', Page, 0);
  72.     if LineNr > 0 then
  73.     begin PickTreeAdd('Filme:', '');
  74.       AddMoviesTitles(Page, LineNr);
  75.       if PickTreeExec(Address) then
  76.          AnalysePage(Address);
  77.     end;
  78.     end;
  79.   end;
  80.   Page.Free;
  81. end;
  82.  
  83. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  84. var
  85.   Line: string;
  86.   MovieTitle, MovieAddress: string;
  87.   StartPos, EndPos: Integer;
  88. begin
  89.   Line := Page.GetString(LineNr);
  90.   repeat
  91.     StartPos := pos('<a href=''view.php?page=film&fid=', Line);
  92.     if StartPos > 0 then
  93.     begin
  94.       Delete(Line, 1, StartPos + 8);
  95.       MovieAddress := copy(Line, 1, pos('''>', Line) - 1);
  96.       StartPos := pos('''>', Line) +2;
  97.       MovieTitle := copy(Line, StartPos, pos('</a>', Line) - StartPos);
  98.       HTMLRemoveTags(MovieTitle);
  99.       PickTreeAdd(MovieTitle , 'http://www.ofdb.de/' + MovieAddress);
  100.     end;
  101.   until (StartPos < 1);
  102. end;
  103.  
  104. procedure AnalyseOFDBPage(Page: TStringList);
  105. var
  106.   Line, Temp, Value: string;
  107.   LineNr, BeginPos, EndPos: Integer;
  108. begin
  109.  
  110.   // Get IMDb URL + Set german IMDb URLs
  111.   begin
  112.     LineNr :=Findline('http://german.imdb.com/Title?', Page, 0);
  113.     Line := Page.GetString(LineNr);
  114.     BeginPos := pos('german.imdb.com/Title?', Line)-7;
  115.     EndPos := pos('target', Line)-2;
  116.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  117.     SetField(fieldURL, Value);
  118.     BeginPos := pos('Title?', Line)+6;
  119.     EndPos := pos('target', Line)-2;
  120.     Temp := copy(Line, BeginPos, EndPos - BeginPos);
  121.     Value := ('http://german.imdb.com/Details?' + Temp);
  122.     GerIMDbDURL := Value;
  123.     Value := ('http://us.imdb.com/Title?' + Temp);
  124.     IMDbURL := Value;
  125.   end;
  126.  
  127.   // Description
  128.   LineNr := Findline('<b>Inhalt:</b>', Page, 0);
  129.   if LineNr > -1 then
  130.   begin
  131.     LineNr :=Findline('<a href=''view.php?page=inhalt', Page, 0);
  132.     Line := Page.GetString(LineNr);
  133.     BeginPos := pos('<a href=''view.php?page=inhalt', Line)+9;
  134.     EndPos := pos('''><b>[mehr]', Line);
  135.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  136.     GetDescriptions(Value);
  137.   end;
  138. end;
  139.  
  140. procedure GetDescriptions(Address: string);
  141. var
  142.   Line, Temp, Value: string;
  143.   LineNr, BeginPos, EndPos: Integer;
  144.   Page: TStringList;
  145.  
  146. begin
  147.   Temp:= '';
  148.   Page := TStringList.Create;
  149.   Page.Text := GetPage('http://www.ofdb.de/' + Address);
  150.   LineNr := FindLine('Eine Inhaltsangabe von', Page, 0);
  151.   if LineNr > -1 then
  152.   begin
  153.     Line := Page.GetString(LineNr);
  154.     BeginPos := pos('</a></b><br><br>', Line) + 16;
  155.     while (pos('<br />', Line) >0) do
  156.          begin
  157.            EndPos := pos('<br />', Line);
  158.            Temp := Temp + copy(Line, BeginPos, EndPos - BeginPos);
  159.            LineNr:=LineNr+1;
  160.            Line:=Page.GetString(LineNr);
  161.            BeginPos:=1;
  162.          end;    
  163.     EndPos := pos('</font></p>', Line);
  164.     Temp:= Temp +  copy(Line, BeginPos, EndPos - BeginPos);
  165.     Value:= Temp;
  166.     SetField(fieldDescription, Value);
  167.   end;
  168.   Page.Free;
  169. end;
  170.  
  171. procedure AnalyseIMDBDPage(Page: TStringList);
  172. var
  173.   Line, Value, Value2, FullValue, GerTitle, Ger, Temp: string;
  174.   BeginPos, EndPos, LineNr, TempPos: Integer;
  175. begin
  176.  
  177.   Page.Text := GetPage(GerIMDbDURL);
  178.  
  179.   //Producer
  180.   LineNr := FindLine('<a name="producers"', Page, 0);
  181.   if LineNr > -1 then
  182.   begin
  183.     FullValue := '';
  184.     EndPos := 0;
  185.     Line := Page.GetString(LineNr);
  186.     BeginPos := Pos('<b class="blackcatheader">Produktion', Line);
  187.     EndPos := Pos('<a name="music_original"', Line);
  188.     if EndPos = 0 then
  189.     begin
  190.     EndPos := Pos('<a name="cinematographers"', Line);
  191.     end;
  192.     Line := copy(Line, BeginPos, EndPos - BeginPos);
  193.     repeat
  194.       BeginPos := Pos('<td valign="top">', Line);
  195.       if BeginPos > 0 then
  196.       begin
  197.         Delete(Line, 1, BeginPos + 25);
  198.         TempPos := Pos('">producer</a>', Line);
  199.         if (TempPos > 0) and (TempPos < Pos('</tr>', Line)) then
  200.         begin
  201.           BeginPos := pos('">', Line) + 2;
  202.           EndPos := pos('</a>', Line);
  203.           if EndPos = 0 then
  204.             EndPos := Pos('</td>', Line);
  205.           Value := copy(Line, BeginPos, EndPos - BeginPos);
  206.           if FullValue <> '' then
  207.             FullValue := FullValue + ', ';
  208.           FullValue := FullValue + Value;
  209.           EndPos := Pos('</td></tr>', Line);
  210.           Delete(Line, 1, EndPos);
  211.         end;
  212.       end else
  213.       begin
  214.         Line := '';
  215.       end;
  216.     until Line = '';
  217.     HTMLDecode(FullValue);
  218.     SetField(fieldProducer, FullValue);
  219.   end;
  220.  
  221.   // Translated Title
  222.   LineNr := FindLine('<i class="transl">', Page, 0);
  223.   if LineNr > -1 then
  224.     begin
  225.       Ger := '';
  226.       LineNr := LineNr - 1;
  227.       repeat
  228.       LineNr := LineNr + 1;
  229.       Line := Page.GetString(LineNr);
  230.         if Pos('[de]', Line) or Pos('(Germany)', Line) > 0 then
  231.         begin
  232.         BeginPos := pos('class="transl">', Line) + 14;
  233.         EndPos := pos('[de]', Line);
  234.         Ger := copy(Line, BeginPos, EndPos - BeginPos);
  235.         end;
  236.       until (pos('<b class="ch">', Line) > 0 );
  237.       BeginPos := pos('>', Ger) + 1;
  238.       EndPos := pos('(', Ger) - 1;
  239.       GerTitle := copy(Ger, BeginPos, EndPos - BeginPos);
  240.       HTMLDecode(GerTitle);
  241.       SetField(fieldTranslatedTitle, GerTitle);
  242.     end;
  243. end;
  244.  
  245. procedure AnalyseIMDBPage(Page: TStringList);
  246. var
  247.   Line, Value, Value2, FullValue: string;
  248.   BeginPos, EndPos, LineNr: Integer;
  249. begin
  250.  
  251.   // Original Title & Year
  252.   Page.Text := GetPage(IMDbURL);
  253.   LineNr := FindLine('<title>', Page, 0);
  254.   Line := Page.GetString(LineNr);
  255.   if LineNr > -1 then
  256.   begin
  257.     BeginPos := pos('<title>', Line);
  258.     if BeginPos > 0 then
  259.       BeginPos := BeginPos + 7;
  260.       EndPos := pos('(', Line);
  261.     if EndPos = 0 then
  262.       EndPos := Length(Line);
  263.     Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
  264.     HTMLDecode(Value);
  265.     SetField(fieldOriginalTitle, Value);
  266.     BeginPos := pos('(', Line) + 1;
  267.     if BeginPos > 0 then
  268.     begin
  269.       EndPos := pos(')', Line);
  270.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  271.       SetField(fieldYear, Value);
  272.     end;
  273.   end;
  274.  
  275.   // Rating
  276.   LineNr := FindLine('User Rating:', Page, 0);
  277.   if LineNr > -1 then
  278.   begin
  279.       Line := Page.GetString(LineNr + 4);
  280.       if Pos('awaiting', Line) = 0 then
  281.       begin
  282.       Line := Page.GetString(LineNr + 4);
  283.       BeginPos := pos('<b>', Line) + 3;
  284.       EndPos := BeginPos + 1;
  285.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  286.       SetField(fieldRating, Value);
  287.       end;
  288.   end;
  289.  
  290.   // Director
  291.   LineNr := FindLine('Directed by', Page, 0);
  292.   if LineNr > -1 then
  293.   begin
  294.     FullValue := '';
  295.     Line := Page.GetString(LineNr + 1);
  296.     repeat
  297.       BeginPos := pos('">', Line) + 2;
  298.       EndPos := pos('</a>', Line);
  299.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  300.       if (Value <> '(more)') and (Value <> '') then
  301.       begin
  302.         if FullValue <> '' then
  303.           FullValue := FullValue + ', ';
  304.         FullValue := FullValue + Value;
  305.       end;
  306.       Delete(Line, 1, EndPos);
  307.     until Pos('</a>', Line) = 0;
  308.     HTMLDecode(FullValue);
  309.     SetField(fieldDirector, FullValue);
  310.   end;
  311.  
  312.   // Actors
  313.   LineNr := FindLine('Cast overview', Page, 0);
  314.   if LineNr = -1 then
  315.     LineNr := FindLine('cast overview', Page, 0);
  316.   if LineNr = -1 then
  317.     LineNr := FindLine('Credited cast', Page, 0);
  318.   if LineNr = -1 then
  319.     LineNr := FindLine('Complete credited cast', Page, 0);
  320.   if LineNr > -1 then
  321.   begin
  322.     FullValue := '';
  323.     Line := Page.GetString(LineNr);
  324.     repeat
  325.       BeginPos := Pos('<td valign="top">', Line);
  326.       if BeginPos > 0 then
  327.       begin
  328.         Delete(Line, 1, BeginPos);
  329.         Line := copy(Line, 25, Length(Line));
  330.         BeginPos := pos('">', Line) + 2;
  331.         EndPos := pos('</a>', Line);
  332.         if EndPos = 0 then
  333.           EndPos := Pos('</td>', Line);
  334.         Value := copy(Line, BeginPos, EndPos - BeginPos);
  335.         if (Value <> '(more)') and (Value <> '') then
  336.         begin
  337.           BeginPos := pos('.... </td><td valign="top">', Line);
  338.           if BeginPos > 0 then
  339.           begin
  340.             EndPos := pos('</td></tr>', Line);
  341.             BeginPos := BeginPos + 27;
  342.             Value2 := copy(Line, BeginPos, EndPos - BeginPos);
  343.             if Value2 <> '' then
  344.             begin
  345.               Value := Value + ' (als ' + Value2 + ')';
  346.             end;
  347.           end;
  348.           if FullValue <> '' then
  349.             FullValue := FullValue + ', ';
  350.           FullValue := FullValue + Value;
  351.         end;
  352.         EndPos := Pos('</td></tr>', Line);
  353.         Delete(Line, 1, EndPos);
  354.       end else
  355.       begin
  356.         Line := '';
  357.       end;
  358.     until Line = '';
  359.     HTMLDecode(FullValue);
  360.     SetField(fieldActors, FullValue);
  361.   end;
  362.  
  363.   //Country
  364.   LineNr := FindLine('Country:', Page, 0);
  365.   if LineNr > -1 then
  366.   begin
  367.     Line := Page.GetString(LineNr + 1);
  368.     BeginPos := pos('/">', Line) + 3;
  369.     EndPos := pos('</a>', Line);
  370.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  371.     HTMLDecode(Value);
  372.     SetField(fieldCountry, Value);
  373.   end;
  374.  
  375.   //Category
  376.   LineNr := FindLine('Genre:', Page, 0);
  377.   if LineNr > -1 then
  378.   begin
  379.     Line := Page.GetString(LineNr + 1);
  380.     BeginPos := pos('/">', Line) + 3;
  381.     EndPos := pos('</a>', Line);
  382.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  383.     HTMLDecode(Value);
  384.     SetField(fieldCategory, Value);
  385.   end;
  386. end;
  387.  
  388. begin
  389.   if CheckVersion(3,3,0) then
  390.   begin
  391.     MovieName := GetField(fieldTranslatedTitle);
  392.     if MovieName = '' then
  393.       MovieName := GetField(fieldOriginalTitle);
  394.     if MovieName = '' then
  395.     begin
  396.       Input('OFDb', 'Bitte Titel eingeben :', MovieName)
  397.       AnalysePage('http://www.ofdb.de/view.php?page=suchergebnis&SText='+UrlEncode(MovieName)+'&Kat=All');
  398.     end else
  399.     begin
  400.       AnalysePage('http://www.ofdb.de/view.php?page=suchergebnis&SText='+UrlEncode(MovieName)+'&Kat=All');
  401.     end;
  402.   end else
  403.     ShowMessage('Dieses Script ben÷tigt eine neuere Version von Ant Movie Catalog (mindestens Version 3.3.0)');
  404. end.
  405.